stanfordfandomcom-20200214-history
Main/asp dotNet
* What: Microsoft ASP.net * Who: Nopparut Abhinoraseth (Big), Zheren Zhang = Writeup Draft = (To be continued...) (TODO: divide it into sections) Microsoft ASP.NET is a server-side framework that allows programmers to develop dynamic web applications. ASP.NET combines unprecedented developer productivity with performance, reliability, and deployment. As a part of .NET Framework, ASP.NET provides an unprecedented flexibility in programming language choice. We learned in class that there are many different server-side technologies such as PHP, JSP, and Ruby on Rails, just to name a few. Most of these traditional server-side technologies, however, are constrained in terms of development languages they offer and typically tie programmers to a very specific technology and language. On the other hand, ASP.NET has full access to more than 40 programming languages provided by .NET Framework, and most of them could be used to develop web applications. When building web applications using ASP.NET, web developers write application logic in their favorite programming language. For example, C++ fans do not need to learn PHP in order to develop a web application and they can write their application logic in C++, and those Java folks can code in J++ (Microsoft’s implementation of Java specification). This flexibility in language choice allows programmers to leverage their existing programming skills and thereby help reduce the learning curve significantly and increase developer productivity. The separation of application logic and presentation logic is another feature that greatly facilitates application development. As we all know that, programmers do not make great designers, and designers are often poor engineers. It is for this reason that most web application companies usually split their projects into two groups – visual design and functional implementation. However, under traditional server-side technologies, code is scattered all over the place and intermingled with the presentation elements. It is extremely difficult for design and coding to be done at the same time. Furthermore, managing the code between designers and programmers can be tricky as well. For instance, updates to a page often introduce new bugs because of a lack of understanding between designers and programmers and no separation between the presentation elements and application logic. To tackle this problem, ASP.NET separates application logic from visual design so that code developers to work separately from the presentation designers who lay out individual pages. This is achieved through a method called code-behind. The idea is to keep all of presentational elements (controls) inside the .aspx file but to move all of code to a separate class in a .vb or .cs code-behind file. Consider the following ASP.NET page, which displays a simple button and label: CS349W Project 2 Example 1 Let's see how this example could be separated into the following distinct files: .aspx file layout, presentation, and static content .aspx.cs file (the exact extension depends on the language you use; .cs is for C#) code-behind files containing a custom page class First, we take all the code and place it in a .aspx.cs file. This file is a pure code file, and contains no HTML or other markup tags. Nevertheless, we can still access presentation elements from this file, using their IDs (such as messageLabel) as shown below: using System; using System.Web.UI; using System.Web.UI.WebControls; public partial class CodeBehindModel: System.Web.UI.Page { public void Click(Object s, EventArgs e) { messageLabel.Text = "Code-Behind Model"; } } Without code, the main ASP.NET page becomes a bit simpler: <%@ Page Language="C#" CodeFile="CodeBehindModel.aspx.cs" Inherits="CodeBehindModel"%> CS349W Project 2 Example 1 As you can see, the separation of visual elements and application logic can make managing and using our pages much more straightforward than keeping your code in code declaration blocks. = What is ASP.NET = ASP.NET is a web application framework developed by Microsoft, that programmers can use to build dynamic web sites, web applications and web services. ASP.NET is built on the Common Language Runtime (CLR) (which is kind of Microsoft's Java Virtual Machine), allowing programmers to write ASP.NET code using any supported .NET language (e.g., C#, C++, java, vb). To develop ASP.NET web application, we normally use Visual Studio.NET. Although, there are many other IDEs that can be used to develop ASP.NET. (need more desc... Give a brief overview describing the general facilities in the package.) = Characteristics = (todo) We need to have some images here (or where?) There are many characteristics of ASP.NET, but a couple of the most important ones are: Pages ASP.NET pages, known as "web forms", are the main building block for application development. Web forms are contained in files with an ASPX extension; these files typically contain static HTML markup, as well as markup defining server-side Web Controls where the developers place all the required static and dynamic content for the web page. Normally, ".aspx" files will be generated automatically by Visual Studio.NET. Additionally, dynamic code which runs on the server can be placed in a page within a block <% -- dynamic code -- %> which is similar to other web development technologies such as PHP, JSP, and ASP, but this practice is generally discouraged except for the purposes of data binding since it requires more calls when rendering the page. Please note that in most cases, the code that will be run on the server will be placed on separate files (next topic), but here we will show one example that uses code "inline", as opposed to code behind. <%@ Page Language="C#" %> Sample page The current time is: Code-behind model It is recommended by Microsoft for dealing with dynamic program code to use the code-behind model, which places this code in a separate file or in a specially designated script tag. Code-behind files typically have names like MyPage.aspx.cs or MyPage.aspx.vb based on the ASPX file name (this practice is automatic in Microsoft Visual Studio and other IDEs). When using this style of programming, the developer writes code to respond to different events, like the page being loaded, or a control being clicked, rather than a procedural walk through the document. ASP.NET's code-behind model marks a departure from Classic ASP in that it encourages developers to build applications with separation of presentation and content in mind. In theory, this would allow a web designer, for example, to focus on the design markup with less potential for disturbing the programming code that drives it. This is similar to the separation of the controller from the view in model-view-controller frameworks. ' Example ' <%@ Page Language="C#" CodeFile="SampleCodeBehind.aspx.cs" Inherits="Website.SampleCodeBehind" AutoEventWireup="true" %> The above tag is placed at the beginning of the ASPX file. The CodeFile property of the @ Page directive specifies the file (.cs or .vb) acting as the code-behind while the Inherits property specifies the Class the Page derives from. In this example, the @ Page directive is included in SamplePage.aspx, then SampleCodeBehind.aspx.cs acts as the code-behind for this page: using System; namespace Website { public partial class SampleCodeBehind : System.Web.UI.Page { protected override void Page_Load(EventArgs e) { base.OnLoad(e); } } } In this case, the Page_Load() method is called every time the ASPX page is requested. The programmer can implement event handlers at several stages of the page execution process to perform processing. State management ' Application state ' ' Session state ' ' View state ' = Creating a web app = * Give a specific example illustrating how the package might be used and how it makes it easier to develop Web applications. (todo) web app to calculate age using calender and textbox. -- full of controls come with .NET = Unique, Advantages, Cool idea = * What is most unique about this package? How is it different from other things you have seen or that we have discussed in class? No "embed code in html" headache problem Everything written in pure c code. E.g., create table with different color for even and odd row. No need to do CSS. * Clean separation of HTML and code * Code in any Visual Studio language (C#, VB, C++, J#) * Easier reuse * Simpler maintenance * Deployment without source code How to improve? * do client side things = Reception = * Critique: what do you think are the best things about this package? What are its greatest weaknesses? Are there particular kinds of applications for which this package is particularly well-suited? :) * ... :( * Everything has to be processed at server. More round-trip * It's Microsoft's product. * $1,000